package com.colorlight.cloud.complete.entity.enumerate;

import com.colorlight.cloud.common.exception.ParameterException;
import com.colorlight.cloud.common.model.ExceptionEnum;

import com.colorlight.cloud.complete.entity.event.*;
import com.colorlight.cloud.complete.entity.instructions.*;
import com.colorlight.cloud.gateway.api.message.constraint.protocol.ProtocolType;
import com.colorlight.cloud.gateway.api.message.constraint.schedule.ScheduleActions;
import com.iot.proto.type.ProtocolSummationType;
import lombok.Getter;

import java.util.Arrays;
import java.util.Objects;

/**
 * @author Demon
 * proto方法类型
 */
@Getter
public enum NameStruct implements ProtocolType {
	// 指令-------------------------------------------------------------------------------------------------------------------
	/**
	 * 参数设置
	 */
	ParamSetInstruction(ProtocolSummationType.NameStruct.ParamSetInstruction, ParamSet.class),
	
	/**
	 * 参数查询方法
	 */
	ParamGetInstruction(ProtocolSummationType.NameStruct.ParamGetInstruction, ParamGet.class),
	
	/**
	 * 获取发送卡电源状态
	 */
	GetSenderPowerStatusInstruction(ProtocolSummationType.NameStruct.GetSenderPowerStatusInstruction, GetSenderPowerStatus.class),
	
	/**
	 * 控制发送卡休眠唤醒 控制休眠唤醒
	 */
	SetSenderPowerCtrlInstruction(ProtocolSummationType.NameStruct.SetSenderPowerCtrlInstruction, SetSenderPowerCtrl.class),
	
	/**
	 * 控制继电器J9toJ12 j13-16状态
	 */
	SetPowerRelayStatusInstruction(ProtocolSummationType.NameStruct.SetPowerRelayStatusInstruction, SetPowerRelayStatus.class),
	
	/**
	 * 获取继电器J9toJ12 j13-16状态
	 */
	GetPowerRelayStatusInstruction(ProtocolSummationType.NameStruct.GetPowerRelayStatusInstruction, GetPowerRelayStatus.class),
	
	/**
	 * 请求接收卡信息 将主动上报改为手动获取 可以加入播放盒
	 */
	GetReceiverInfoInstruction(ProtocolSummationType.NameStruct.GetReceiverInfoInstruction, GetReceiverInfo.class),
	
	/**
	 * 获取发送卡信息
	 */
	GetSenderDeviceInfoInstruction(ProtocolSummationType.NameStruct.GetSenderDeviceInfoInstruction, GetSenderDeviceInfo.class),
	
	/**
	 * 获取多功能卡状态
	 */
	GetMultiFunctionInfoInstruction(ProtocolSummationType.NameStruct.GetMultiFunctionInfoInstruction, GetMultiFunctionInfo.class),
	
	/**
	 * 回读连接关系
	 */
	GetReceiverMappingInstruction(ProtocolSummationType.NameStruct.GetReceiverMappingInstruction, GetReceiverMapping.class),
	
	/**
	 * 固化接收卡参数
	 */
	SetReceiverParameterRequestInstruction(ProtocolSummationType.NameStruct.SetReceiverParameterRequestInstruction, SetReceiverParameterRequest.class),
	
	/**
	 * 固化连接关系-json
	 */
	SetReceiverJsonInstruction(ProtocolSummationType.NameStruct.SetReceiverJsonInstruction, SetReceiverJson.class),
	
	/**
	 * 固化连接关系-file
	 * 异步事件:SetConnectedRelationFinish
	 */
	SetReceiverFileInstruction(ProtocolSummationType.NameStruct.SetReceiverFileInstruction, SetReceiverFile.class),
	
	/**
	 * 除湿配置
	 */
	SetDehumidificationParameterInstruction(ProtocolSummationType.NameStruct.SetDehumidificationParameterInstruction, SetDehumidificationParameter.class),
	
	/**
	 * 查询除湿配置
	 */
	GetDehumidificationParameterInstruction(ProtocolSummationType.NameStruct.GetDehumidificationParameterInstruction, GetDehumidificationParameter.class),
	
	/**
	 * 设置指令排程
	 * 设置高级控制
	 */
	SetCommandScheduleInstruction(ProtocolSummationType.NameStruct.SetCommandScheduleInstruction, SetCommandSchedule.class),
	
	/**
	 * 获取指令排程
	 * 获取高级控制
	 */
	GetCommandScheduleInstruction(ProtocolSummationType.NameStruct.GetCommandScheduleInstruction, GetCommandSchedule.class),
	
	/**
	 * 获取屏幕亮度
	 */
	GetBrightnessInstruction(ProtocolSummationType.NameStruct.GetBrightnessInstruction, GetBrightness.class),
	
	/**
	 * 设置屏幕亮度
	 */
	SetBrightnessInstruction(ProtocolSummationType.NameStruct.SetBrightnessInstruction, SetBrightness.class),
	
	/**
	 * 获取屏幕色温
	 */
	GetColorTemperatureInstruction(ProtocolSummationType.NameStruct.GetColorTemperatureInstruction, GetColorTemperature.class),
	
	/**
	 * 设置屏幕色温
	 * 播放盒设置和响应都只用其中的prcIndex与colorTemperature字段
	 */
	SetColorTemperatureInstruction(ProtocolSummationType.NameStruct.SetColorTemperatureInstruction, SetColorTemperature.class),
	
	/**
	 * 获取屏幕冻结状态
	 */
	GetScreenLockInstruction(ProtocolSummationType.NameStruct.GetScreenLockInstruction, GetScreenLock.class),
	
	/**
	 * 设置屏幕冻结状态
	 */
	SetScreenLockInstruction(ProtocolSummationType.NameStruct.SetScreenLockInstruction, SetScreenLock.class),
	
	/**
	 * 发送卡参数文件上传
	 * 异步事件：SenderFileUploadFinish
	 */
	SetSenderFileUploadInstruction(ProtocolSummationType.NameStruct.SetSenderFileUploadInstruction, SetSenderFileUpload.class),
	
	/**
	 * 发送卡参数文件下载
	 * 异步事件：SenderFileDownloadFinish
	 */
	GetSenderFileDownloadInstruction(ProtocolSummationType.NameStruct.GetSenderFileDownloadInstruction, GetSenderFileDownload.class),
	
	/**
	 * 设置多功能卡继电器自动控制参数
	 */
	SetPowerRelayAutoInstruction(ProtocolSummationType.NameStruct.SetPowerRelayAutoInstruction, SetPowerRelayAuto.class),
	
	/**
	 * 获取继电器自动控制
	 */
	GetPowerRelayAutoInstruction(ProtocolSummationType.NameStruct.GetPowerRelayAutoInstruction, GetPowerRelayAuto.class),
	
	/**
	 * 设置测试模式
	 */
	SetTestModelInstruction(ProtocolSummationType.NameStruct.SetTestModelInstruction, SetTestModel.class),
	
	/**
	 * 获取测试模式
	 */
	GetTestModelInstruction(ProtocolSummationType.NameStruct.GetTestModelInstruction, GetTestModel.class),
	
	/**
	 * 读取预置
	 * 发送设备获取预置
	 */
	GetPresetInstruction(ProtocolSummationType.NameStruct.GetPresetInstruction, GetPreset.class),
	
	/**
	 * 加载预置
	 * 发送设备设置预置
	 */
	SetPresetInstruction(ProtocolSummationType.NameStruct.SetPresetInstruction, SetPreset.class),
	
	/**
	 * 保存预置
	 * 发送设备保存预置
	 */
	SavePresetInstruction(ProtocolSummationType.NameStruct.SavePresetInstruction, SavePreset.class),
	
	/**
	 * 发送卡恢复出厂
	 * 上报异步：SetFactoryRestoreFinishEvent
	 */
	SetFactoryRestoreInstruction(ProtocolSummationType.NameStruct.SetFactoryRestoreInstruction, SetFactoryRestore.class),
	
	/**
	 * 多功能卡恢复出厂
	 * 上报异步：FunctionFactoryRestoreFinishEvent
	 */
	FunctionFactoryRestoreInstruction(ProtocolSummationType.NameStruct.FunctionFactoryRestoreInstruction, FunctionFactoryRestore.class),
	
	/**
	 * 配置摄像头参数
	 * 配置摄像头信息
	 */
	ConfigCameraInstruction(ProtocolSummationType.NameStruct.ConfigCameraInstruction, ConfigCamera.class),
	
	/**
	 * 配置摄像头截图上传地址信息
	 * 摄像连接设置
	 */
	ConfigUploadUrlInstruction(ProtocolSummationType.NameStruct.ConfigUploadUrlInstruction, ConfigUploadUrl.class),
	
	/**
	 * 旧除湿配置
	 */
	SetOldDehumidificationParameterInstruction(ProtocolSummationType.NameStruct.SetOldDehumidificationParameterInstruction, SetOldDehumidificationParameter.class),
	
	/**
	 * 查询旧除湿配置
	 */
	GetOldDehumidificationParameterInstruction(ProtocolSummationType.NameStruct.GetOldDehumidificationParameterInstruction, GetOldDehumidificationParameter.class),
	
	/**
	 * 删除屏体
	 */
	DeleteScreenInstruction(ProtocolSummationType.NameStruct.DeleteScreenInstruction, DeleteScreen.class),
	
	/**
	 * 设备注销 通知不到 仍然删除  连不上重新获取
	 */
	RemoveDeviceInstruction(ProtocolSummationType.NameStruct.RemoveDeviceInstruction, RemoveDevice.class),
	
	/**
	 * 设置自动亮度
	 */
	SetAutoBrightnessInstruction(ProtocolSummationType.NameStruct.SetAutoBrightnessInstruction, SetAutoBrightness.class),
	
	/**
	 * 获取自动亮度
	 */
	GetAutoBrightnessInstruction(ProtocolSummationType.NameStruct.GetAutoBrightnessInstruction, GetAutoBrightness.class),
	
	/**
	 * 设置整屏休眠唤醒
	 */
	SetAllSenderPowerInstruction(ProtocolSummationType.NameStruct.SetAllSenderPowerInstruction, SetAllSenderPower.class),
	
	/**
	 * 设置整屏亮度
	 */
	SetAllBrightnessInstruction(ProtocolSummationType.NameStruct.SetAllBrightnessInstruction, SetAllBrightness.class),
	
	/**
	 * 加密下发指令
	 * 加密下发指令以及返回信息，设备主体和发送卡加解密通用接口
	 */
	EncryptInstruction(ProtocolSummationType.NameStruct.EncryptInstruction, Encrypt.class),
	
	/**
	 * 修改屏幕名称
	 */
	ModifyScreenNameInstruction(ProtocolSummationType.NameStruct.ModifyScreenNameInstruction, ModifyScreenName.class),
	
	/**
	 * 设置继电器定时控制
	 */
	SetRelayTimingInstruction(ProtocolSummationType.NameStruct.SetRelayTimingInstruction, SetRelayTiming.class),
	
	/**
	 * 获取模组坏点数
	 */
	GetModuleDeadPixelInstruction(ProtocolSummationType.NameStruct.GetModuleDeadPixelInstruction, GetModuleDeadPixel.class),
	
	/**
	 * 设置发送设备音量
	 */
	SetSenderVolumeInstruction(ProtocolSummationType.NameStruct.SetSenderVolumeInstruction, SetSenderVolume.class),
	
	/**
	 * 网络同步发送设备加解密信息。设备先同步时间，再返回加解密信息
	 */
	SyncSenderAuthInfoInstruction(ProtocolSummationType.NameStruct.SyncSenderAuthInfoInstruction, SyncSenderAuthInfo.class),
	
	/**
	 * 解密指令
	 */
	DecryptInstruction(ProtocolSummationType.NameStruct.DecryptInstruction, Decrypt.class),
	
	/**
	 * 设置多功能卡时间
	 */
	SetFunctionTimeInstruction(ProtocolSummationType.NameStruct.SetFunctionTimeInstruction, SetFunctionTime.class),
	
	/**
	 * 获取设备信息
	 */
	GetDeviceAuthInfoInstruction(ProtocolSummationType.NameStruct.GetDeviceAuthInfoInstruction, GetDeviceAuthInfo.class),
	
	/**
	 * 定时加密
	 */
	TimingEncryptInstruction(ProtocolSummationType.NameStruct.TimingEncryptInstruction, TimingEncrypt.class),
	
	/**
	 * 获取多功能卡的自动亮度
	 */
	GetFunctionAutoBrightnessInstruction(ProtocolSummationType.NameStruct.GetFunctionAutoBrightnessInstruction, GetFunctionAutoBrightness.class),
	
	/**
	 * 设置多功能卡的自动亮度
	 */
	SetFunctionAutoBrightnessInstruction(ProtocolSummationType.NameStruct.SetFunctionAutoBrightnessInstruction, SetFunctionAutoBrightness.class),
	
	/**
	 * 更新设备
	 */
	UpdateDeviceInstruction(ProtocolSummationType.NameStruct.UpdateDeviceInstruction, UpdateDevice.class),
	
	/**
	 * 屏幕截图上报
	 */
	UploadScreenshotInstruction(ProtocolSummationType.NameStruct.UploadScreenshotInstruction, UploadScreenshot.class),
	
	/**
	 * 获取m2外接亮度传感器数据
	 */
	GetM2BrightnessInstruction(ProtocolSummationType.NameStruct.GetM2BrightnessInstruction, GetM2Brightness.class),
	
	/**
	 * 设置接收卡温控继电器
	 */
	SetReceiverTemperatureControlInstruction(ProtocolSummationType.NameStruct.SetReceiverTemperatureControlInstruction, SetReceiverTemperatureControl.class),
	
	/**
	 * 模组温度控制
	 */
	SetModuleTemperatureControlInstruction(ProtocolSummationType.NameStruct.SetModuleTemperatureControlInstruction, SetModuleTemperatureControl.class),
	
	/**
	 * 设置M2自动继电器
	 */
	SetM2AutoRelayInstruction(ProtocolSummationType.NameStruct.SetM2AutoRelayInstruction, SetM2AutoRelay.class),
	
	/**
	 * 设置M2继电器状态
	 */
	SetM2RelayInstruction(ProtocolSummationType.NameStruct.SetM2RelayInstruction, SetM2Relay.class),
	
	/**
	 * 重启设备
	 */
	RebootInstruction(ProtocolSummationType.NameStruct.RebootInstruction, Reboot.class),
	
	/**
	 * 配置设备输入模式
	 */
	SetInputModeInstruction(ProtocolSummationType.NameStruct.SetInputModeInstruction, SetInputMode.class),
	
	/**
	 * 升级接收卡FPGA
	 */
	UpdateReceiverInstruction(ProtocolSummationType.NameStruct.UpdateReceiverInstruction, UpdateReceiver.class),
	
	/**
	 * 保存多功能卡设置
	 */
	SaveFunctionSettingInstruction(ProtocolSummationType.NameStruct.SaveFunctionSettingInstruction, SaveFunctionSetting.class),
	
	/**
	 * 回读接收卡连接关系文件
	 */
	GetReceiverMappingFileInstruction(ProtocolSummationType.NameStruct.GetReceiverMappingFileInstruction, GetReceiverMappingFile.class),
	
	/**
	 * 回读接收卡参数文件
	 */
	GetReceiverParamFileInstruction(ProtocolSummationType.NameStruct.GetReceiverParamFileInstruction, GetReceiverParamFile.class),
	
	/**
	 * 重置误码率
	 */
	ResetReceiverErrorRateInstruction(ProtocolSummationType.NameStruct.ResetReceiverErrorRateInstruction, ResetReceiverErrorRate.class),
	
	/**
	 * 设置时间时区，支持网络同步
	 */
	SetTimeZoneInstruction(ProtocolSummationType.NameStruct.SetTimeZoneInstruction, SetTimeZone.class),
	
	/**
	 * 设置im9风扇状态
	 */
	SetIm9FanStatusInstruction(ProtocolSummationType.NameStruct.SetIm9FanStatusInstruction, SetIm9FanStatus.class),
	
	/**
	 * 测试网络延迟，获取延迟时间
	 */
	TestNetworkLatencyInstruction(ProtocolSummationType.NameStruct.TestNetworkLatencyInstruction, TestNetworkLatency.class),
	
	/**
	 * 删除发送设备
	 */
	DeleteSenderInstruction(ProtocolSummationType.NameStruct.DeleteSenderInstruction, DeleteSender.class),
	
	/**
	 * 获取多功能卡事件
	 */
	GetFunctionTimeInstruction(ProtocolSummationType.NameStruct.GetFunctionTimeInstruction, GetFunctionTime.class),
	
	/**
	 * 获取位置信息
	 */
	GetLocationInstruction(ProtocolSummationType.NameStruct.GetLocationInstruction, GetLocation.class),
	
	/**
	 * 获取位置信息
	 */
	GetTimeZoneInstruction(ProtocolSummationType.NameStruct.GetTimeZoneInstruction, GetTimeZone.class),
	
	// 事件-------------------------------------------------------------------------------------------------------------------
	/**
	 * 心跳
	 */
	HBEvent(ProtocolSummationType.NameStruct.HBEvent, HB.class),
	
	/**
	 * 定义:开机事件 设备网络变化 开机后 会影响到的数据上报 没有数据 制作定义 不上报
	 */
	DeviceStartEvent(ProtocolSummationType.NameStruct.DeviceStartEvent, DeviceStart.class),
	
	/**
	 * 接收卡上报
	 */
	RcvCardMonitorReportEvent(ProtocolSummationType.NameStruct.RcvCardMonitorReportEvent, RcvCardMonitorReport.class),
	
	/**
	 * 定时上报 发送卡监控数据上报
	 */
	SenderMonitorReportEvent(ProtocolSummationType.NameStruct.SenderMonitorReportEvent, SenderMonitorReport.class),
	
	/**
	 * 多功能卡上报
	 */
	FunctionCardsMonitorReportEvent(ProtocolSummationType.NameStruct.FunctionCardsMonitorReportEvent, FunctionReport.class),
	
	/**
	 * 连接关系固化完成上报事件
	 * 事件名称: 固化连接关系完成事件
	 * 定义: json、file固化连接关系上报
	 */
	SetConnectedRelationFinishEvent(ProtocolSummationType.NameStruct.SetConnectedRelationFinishEvent, SetConnectedRelationFinish.class),
	
	/**
	 * 接收卡参数固化完成上报事件
	 */
	ReceiverResultFinishEvent(ProtocolSummationType.NameStruct.ReceiverResultFinishEvent, ReceiverResultFinish.class),
	
	/**
	 * 遗嘱消息: 设备离线后的通知
	 * 只做下线的通知
	 */
	OffLineEvent(ProtocolSummationType.NameStruct.OffLineEvent, OffLine.class),
	
	/**
	 * 执行异常结果上报
	 */
	ExecuteUploadEvent(ProtocolSummationType.NameStruct.ExecuteUploadEvent, ExecuteUpload.class),
	
	/**
	 * 发送卡参数上报事件
	 */
	SenderFileUploadFinishEvent(ProtocolSummationType.NameStruct.SenderFileUploadFinishEvent, SenderFileUploadFinish.class),
	
	/**
	 * 发送卡参数下载事件
	 */
	SenderFileDownloadFinishEvent(ProtocolSummationType.NameStruct.SenderFileDownloadFinishEvent, SenderFileDownloadFinish.class),
	/**
	 * 发送卡恢复出厂上报事件
	 */
	SetFactoryRestoreFinishEvent(ProtocolSummationType.NameStruct.SetFactoryRestoreFinishEvent, SetFactoryRestoreFinish.class),
	
	/**
	 * 多功能卡恢复出厂上报事件
	 */
	FunctionFactoryRestoreFinishEvent(ProtocolSummationType.NameStruct.FunctionFactoryRestoreFinishEvent, FunctionFactoryRestoreFinish.class),
	
	/**
	 * 摄像头截图上报异常上报事件
	 */
	CameraUploadErrorEvent(ProtocolSummationType.NameStruct.CameraUploadErrorEvent, CameraUploadError.class),
	
	/**
	 * 高级控制执行结果上报
	 */
	CommandScheduleResultUploadEvent(ProtocolSummationType.NameStruct.CommandScheduleResultUploadEvent, CommandScheduleResultUpload.class),
	
	/**
	 * 智慧模组监控上报
	 */
	SmartModuleMonitorReportEvent(ProtocolSummationType.NameStruct.SmartModuleMonitorReportEvent, SmartModuleMonitorReport.class),
	
	/**
	 * 下载结果上报
	 */
	DownloadReportEvent(ProtocolSummationType.NameStruct.DownloadReportEvent, DownloadReport.class),
	
	/**
	 * 加解密的自动上报
	 */
	AuthorizationInfoEvent(ProtocolSummationType.NameStruct.AuthorizationInfoEvent, AuthorizationInfo.class),
	
	/**
	 * 外接传感器上报事件
	 */
	SensorReportEvent(ProtocolSummationType.NameStruct.SensorReportEvent, SensorReport.class),
	
	/**
	 * 程序更新上报事件
	 */
	UpdateReportEvent(ProtocolSummationType.NameStruct.UpdateReportEvent, UpdateReport.class),
	
	/**
	 * 屏幕截图上报事件
	 */
	UploadScreenshotReportEvent(ProtocolSummationType.NameStruct.UploadScreenshotReportEvent, UploadScreenshotReport.class),
	
	/**
	 * 接收卡升级上报
	 */
	ReceiverUpdateReportEvent(ProtocolSummationType.NameStruct.ReceiverUpdateReportEvent, ReceiverUpdateReport.class),
	
	/**
	 * 保存多功能卡设置进度上报事件
	 */
	SaveFunctionSettingUploadEvent(ProtocolSummationType.NameStruct.SaveFunctionSettingUploadEvent, SaveFunctionSettingUpload.class),
	
	/**
	 * 回读接收卡连接关系文件上报事件
	 */
	GetReceiverMappingFileUploadEvent(ProtocolSummationType.NameStruct.GetReceiverMappingFileUploadEvent, GetReceiverMappingFileUpload.class),
	
	/**
	 * 回读接收卡参数文件上报事件
	 */
	GetReceiverParamFileUploadEvent(ProtocolSummationType.NameStruct.GetReceiverParamFileUploadEvent, GetReceiverParamFileUpload.class),
	
	/**
	 * 设备主体参数上报
	 */
	GetMainDeviceInfoEvent(ProtocolSummationType.NameStruct.GetMainDeviceInfoEvent, GetMainDeviceInfo.class),
	
	/**
	 * 时间主动上报
	 */
	LocationUploadEvent(ProtocolSummationType.NameStruct.LocationUploadEvent, LocationUpload.class),
	;
	
	private final Integer id;
	private final String name;
	private final ProtocolSummationType.NameStruct nameStruct;
	private final Class<? extends ScheduleActions> aClass;
	
	private static final long serialVersionUID = 123456789123456789L;
	
	NameStruct(ProtocolSummationType.NameStruct nameStruct, Class<? extends ScheduleActions> aClass) {
		this.id = nameStruct.getNumber();
		this.name = nameStruct.name();
		this.aClass = aClass;
		this.nameStruct = nameStruct;
	}
	
	/**
	 * @param aClass 类型
	 * @return 对应的名字
	 **/
	public static NameStruct getNameStructByClass(Class<? extends ScheduleActions> aClass) {
		Objects.requireNonNull(aClass, "TypeNum can not be null.");
		return Arrays.stream(NameStruct.values())
				.filter(nameStruct -> nameStruct.aClass.equals(aClass))
				.findFirst()
				.orElseThrow(() -> new ParameterException(ExceptionEnum.NOT_EXIST_ENUM));
	}
	
	/**
	 * @param struct 原始类型
	 * @return 对应的名字
	 **/
	
	public static NameStruct getNameStructByProtocolSummationType(ProtocolSummationType.NameStruct struct) {
		Objects.requireNonNull(struct, "struct can not be null.");
		return Arrays.stream(NameStruct.values())
				.filter(nameStruct -> nameStruct.nameStruct.equals(struct))
				.findFirst()
				.orElseThrow(() -> new ParameterException(ExceptionEnum.NOT_EXIST_ENUM));
	}
	
	/**
	 * @param aClass 类型
	 * @return 对应的名字
	 **/
	public static String getNameByClass(Class<? extends ScheduleActions> aClass) {
		return getNameStructByClass(aClass).getName();
	}
	
	@Override
	public String getInstructTypeName() {
		return null;
	}
	
	@Override
	public Class<? extends ScheduleActions> getScheduleClass() {
		return this.aClass;
	}
	
	@Override
	public NameStruct getByProtocolSummationType(ProtocolSummationType.NameStruct nameStruct) {
		return getNameStructByProtocolSummationType(nameStruct);
	}
	
	
	@Override
	public String getThisName() {
		return nameStruct.name();
	}
}
